#include<bits/stdc++.h>
using namespace std;
int n,a[9000001],color[9000001]={},b[900001]={};//in color,1 called blue,2 called red,0 means "DONT KNOW"
int FPA(int h){
	for(int i=h+1;i<=n;i++){
		if(a[i]==a[h]){
			a[i]=-1;
			a[h]=-1;
			return i;
		}
	}
	return false;
}
int CPA(int x,int y){
	int bt=0,rt=0;
	for(int i=x+1;i<y;i++){
		if(a[i]==1){
			bt++;
		}
		if(a[i]==2){
			rt++;
		}
		if(a[i]==0){
			if(rt>0 || bt>0){
				rt++;
				bt++;
			}
		}
	}
	if(bt>0 and rt>0){
		return false;
	}
	if(bt==0){
		color[x]=1;
		color[y]=1;
	}
	if(rt==0){
		color[x]=2;
		color[y]=2;
	}
	return true;
}
void GIS(){
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=-1){
			if(FPA(i)!=false){
				if(CPA(i,FPA(i))!=false){
					ans+=b[i];
				}
			}
		}
	}
	cout<<ans<<endl;
	return ;
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;
	cin>>T;
	while(T--){
		GIS();
	}
	return 0;
}
